Skip to content

preprocessor cache: compare time-macro headers by content - #2954

Merged
sylvestre merged 2 commits into
mozilla:mainfrom
lenamonj:preprocessor-cache-time-macro-digest
Nov 27, 2026
Merged

sylvestre merged 2 commits into
mozilla:mainfrom
lenamonj:preprocessor-cache-time-macro-digest

Conversation

@lenamonj

@lenamonj lenamonj commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

With ignore_time_macros off, a header containing __DATE__ or __TIMESTAMP__ is never compared by content on lookup, so a same-size edit is served the old object: result_matches skips the digest check once a time macro is found. The input's __TIMESTAMP__ is not in the entry key either.

Each remembered header is now stored and compared, and the input is keyed, by its content digest plus the date for __DATE__ and its mtime for __TIMESTAMP__; if that mtime can't be read the file is not cached. Files with neither keep their plain digest, so existing entries stay valid. Lookups no longer rewrite entries.

Three new tests fail with the fix undone; two more drive remember_include_file.

@codecov-commenter

codecov-commenter commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.36364% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.14%. Comparing base (2c7ae2e) to head (989282d).

Files with missing lines Patch % Lines
src/compiler/preprocessor_cache.rs 94.59% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2954      +/-   ##
==========================================
+ Coverage   80.03%   80.14%   +0.11%     
==========================================
  Files          76       76              
  Lines       47506    47667     +161     
==========================================
+ Hits        38021    38203     +182     
+ Misses       9485     9464      -21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lenamonj
lenamonj force-pushed the preprocessor-cache-time-macro-digest branch from edcb27c to 238b519 Compare November 7, 2026 18:58
Comment thread src/compiler/preprocessor_cache.rs Outdated
if finder.found_timestamp() {
debug!("found __TIMESTAMP__ in {}", path.display());
m.delimiter(b"timestamp");
if let Ok(mtime) = std::fs::metadata(path).and_then(|meta| meta.modified()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old code returned false when the mtime couldn't be read; here it silently drops the mtime, so a __TIMESTAMP__ header would match whatever its mtime. Is that intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that wasn't intended. If the mtime can't be read the helper now returns None, and the lookup, remember_include_file and the entry key all treat that as a miss, like the old code did. Added a test for it, plus the doc comment and the SOURCE_DATE_EPOCH line.

.collect()
});

pub fn time_macro_adjusted_digest(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a short doc comment, it's pub and called from c.rs

m.update(&date.year().to_le_bytes());
m.update(&date.month().to_le_bytes());
m.update(&date.day().to_le_bytes());
if let Ok(source_date_epoch) = std::env::var("SOURCE_DATE_EPOCH") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment explaining why we hash both SOURCE_DATE_EPOCH and the date got lost, could you please keep a one-line version?

@lenamonj
lenamonj force-pushed the preprocessor-cache-time-macro-digest branch from 238b519 to f4be117 Compare November 21, 2026 04:54
@codspeed

codspeed Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 8.81%

2 warnings

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 1 improved benchmark
✅ 61 untouched benchmarks
⏩ 6 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation preprocessor_cache_lookup 611.6 µs 562.1 µs +8.81%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing lenamonj:preprocessor-cache-time-macro-digest (989282d) with main (2c7ae2e)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@lenamonj
lenamonj force-pushed the preprocessor-cache-time-macro-digest branch from f4be117 to 6343bf9 Compare November 22, 2026 17:38
Comment thread src/compiler/c.rs Outdated
return Ok(false);
}

let Some(file_digest) = time_macro_adjusted_digest(file_digest, &finder, &path) else {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time_macro_adjusted_digest stats the file with std::fs, not fs_impl, so the modified: None TestFs test only passes because the header doesn't exist on disk.
could we pass the mtime from meta here instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helper now takes the mtime as an argument, and remember_include_file passes meta.modified. The test writes the header to disk, so the only reason it gets refused is modified: None - it fails on the previous head. The lookup’s meta is a symlink_metadata while the entry key has none, so both still end up statting the file (following symlinks the same way remember_include_file’s meta does), and that only happens when it uses __TIMESTAMP__.

remember_include_file passes the mtime of the metadata it already read, so the unreadable-mtime test no longer depends on the header being absent from disk.
@lenamonj
lenamonj force-pushed the preprocessor-cache-time-macro-digest branch from 6343bf9 to 989282d Compare November 26, 2026 22:35
@sylvestre
sylvestre merged commit f76e7ae into mozilla:main Nov 27, 2026
51 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

@lenamonj
lenamonj deleted the preprocessor-cache-time-macro-digest branch November 27, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants